/*************************************************************************************
 **																					**
 **	dataflash.c - EE emulation library												**
 ** 																				**
 **************************************************************************************
 **																					**
 ** Written By:	Steve Montgomery													**
 **				Digital Six Laboratories LLC										**
 ** (c)2012,2013,2014 Digital Six Labs, All rights reserved							**
 **																					**
 **************************************************************************************/
//
// Revision History
//
// Revision		Date	Reviser		Description
// ===================================================================================
// ===================================================================================
#include "dataflash.h"

#define EESIZE 200
volatile pfdl_u08 EE_Mirror[EESIZE] __attribute__ ((section (".PFDL_DAT")));

void EEReadByte(U8 addr, U8 *data)
{
	*data =  EE_Mirror[addr];

}

void EEWriteByte(U8 addr, U8 data)
{
	EE_Mirror[addr] = data;
}

U8 EEPersist(void)
{
	/*
	pfdl_descriptor_t pfdl_d;
	pfdl_request_t    pfdl_request;
	pfdl_status_t     pfdl_status;

	// prepare descriptor and open PFDL
	pfdl_d.fx_MHz_u08 = 32;                // system frequency in MHz
	pfdl_d.wide_voltage_mode_u08 = 0x01;   // according to Vdd
	PFDL_Open(&pfdl_d);

	pfdl_request.command_enu = PFDL_CMD_ERASE_BLOCK;
	pfdl_status = PFDL_Execute(&pfdl_request);
	if( (pfdl_status != PFDL_OK) && (pfdl_status != PFDL_BUSY))
	{
		PFDL_Close();
		return 0;
	}
	// wait for execution to complete
	while(pfdl_status == PFDL_BUSY)
	{
	  pfdl_status = PFDL_Handler();
	}
	if(pfdl_status!=PFDL_OK)
	{
		PFDL_Close();
		return 0;
	}
	pfdl_request.index_u16 = 0;
	pfdl_request.bytecount_u16 = 200;
	pfdl_request.data_pu08 = (pfdl_u08*) &EE_Mirror;
	pfdl_request.command_enu = PFDL_CMD_WRITE_BYTES;
	pfdl_status = PFDL_Execute(&pfdl_request);
	if( (pfdl_status != PFDL_OK) && (pfdl_status != PFDL_BUSY))
	{
		PFDL_Close();
		return 0;
	}
	// wait for execution to complete
	while(pfdl_status == PFDL_BUSY)
	{
	  pfdl_status = PFDL_Handler();
	}
	if(pfdl_status!=PFDL_OK)
	{
		PFDL_Close();
		return 0;
	}
	PFDL_Close();
	*/
	return 1;
}
U8 EELoad()
{
	/*
	pfdl_descriptor_t pfdl_d;
	pfdl_request_t    pfdl_request;
	pfdl_status_t     pfdl_status;

	// prepare descriptor and open PFDL
	pfdl_d.fx_MHz_u08 = 32;                // system frequency in MHz
	pfdl_d.wide_voltage_mode_u08 = 0x01;   // according to Vdd
	PFDL_Open(&pfdl_d);

	 pfdl_request.index_u16 = 0;
	pfdl_request.bytecount_u16 = EESIZE;
	pfdl_request.data_pu08 = (pfdl_u08*) &EE_Mirror;
	pfdl_request.command_enu = PFDL_CMD_READ_BYTES;
	pfdl_status = PFDL_Execute(&pfdl_request);
	if( (pfdl_status != PFDL_OK) && (pfdl_status != PFDL_BUSY))
	{
		PFDL_Close();
		return 0;
	}
	// wait for execution to complete
	while(pfdl_status == PFDL_BUSY)
	{
	  pfdl_status = PFDL_Handler();
	}

	if(pfdl_status!=PFDL_OK)
	{
		PFDL_Close();
		return 0;
	}

	PFDL_Close();
	*/
	return 1;
}
